<?php
	include_once("db/UserDAO.inc");
	include_once("db/AccessLevel.inc");
?>

<script language="javascript"><!--
	function deleteUser(uid) {
		var answer = confirm("Are you sure you want to delete the user with UID=" + uid + "?");
		
		if (answer) {
			window.location.href = "?action=deleteUser&uid=" + uid;
		}
	}

--></script>

<table cellspacing="0">
	<tr class="first">
		<td>&nbsp;</td>
		<td>User Name</td>
		<td>First Name</td>
		<td>Surname</td>
		<td>Access Level</td>
		<td>EC #</td>
		<td>Shift</td>
	</tr>
	
<?php
	$userArray = User::getAllUsers();
	foreach ($userArray as $u) {
		$level = AccessLevel::getAccessLevel($u->accessLevel);
		$levelString = "-";
		if (isset($level)) {
			$levelString = $level->id . " - " . $level->description;
		}
		
		$allowMods = false;
		if ($_SESSION["accessLevel"] == 1) $allowMods = true;
		if ($_SESSION["accessLevel"] == 4) $allowMods = ($u->accessLevel != 1) && ($u->accessLevel != 4);
		
		$allowDelete = $allowMods;
		if ($_SESSION["uid"] == $u->uid) $allowDelete = false;
?>

	<tr>
		<td>&nbsp;
<?php
		if ($allowMods) {
?>
			<a href="?action=editUser&uid=<?php print $u->uid ?>" >Edit</a>
<?php
		}
		if ($allowMods && $allowDelete) {
?>
			&nbsp;|&nbsp;
			<a href="javascript:deleteUser(<?php print $u->uid ?>)" >Delete</a>
<?php
		}
?>
		&nbsp;
		</td>
		<td><?php print $u->username ?></td>
		<td><?php print $u->firstName ?>&nbsp;</td>
		<td><?php print $u->surname ?>&nbsp;</td>
		<td><?php print $levelString ?></td>
		<td><?php print $u->ecno ?>&nbsp;</td>
		<td><?php print $u->shift ?>&nbsp;</td>
	</tr>

<?php
	}
?>

</table>